﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace V2TEK.NET.SH.Silverlight.Charts.GanttHelper
{
    public class SimpleSummaryTaskRenderer : AbstractTaskEntryRenderer
    {
        public SimpleSummaryTaskRenderer() : base()
        {
            this.DefaultStyleKey = typeof(SimpleSummaryTaskRenderer);
        }


        protected ColumnDefinition mCompletedCol;
        protected ColumnDefinition mUnCompletedCol;

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            mCompletedCol = (ColumnDefinition)base.GetTemplateChild("mCompletedCol");
            mUnCompletedCol = (ColumnDefinition)base.GetTemplateChild("mUnCompletedCol");
        }

        protected override Size MeasureOverride(Size availableSize)
        {
            //20101020 by ChenYao 不知为啥使用百分比出错
            if (availableSize.Width > 0)
            {
                if (mCompletedCol != null && mUnCompletedCol != null)
                {
                    mCompletedCol.Width = new GridLength(availableSize.Width * Data.PercentComplete * 0.01);
                    mUnCompletedCol.Width = new GridLength(1, GridUnitType.Auto);
                }
            }

            return base.MeasureOverride(availableSize);
        }
    }
}
